﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
using System.Data.SQLite;
using MedicLibrary.Model;
using MedicLibrary.View;

namespace MedicLibrary.Controler
{
    public class Session
    {
        public static int Num = -1;
        public static int IDThuoc = -1;
        public static int IDNhomThuoc = -1;
        public static int IDNhomCha = -1;
        public static int IDHoatChat = -1;
        public static int IDHangSX = -1;
        
        public static String generateID(int NumNo, int ID)
        {
            String re = "ERROR";
            switch (NumNo - ID.ToString().Length)
            {
                case 0:
                    re = "";
                    break;
                case 1:
                    re = "0";
                    break;
                case 2:
                    re = "00";
                    break;
                case 3:
                    re = "000";
                    break;
                case 4:
                    re = "0000";
                    break;
                case 5:
                    re = "00000";
                    break;
                case 6:
                    re = "000000";
                    break;
            }
            return re + ID.ToString();
        }

        public static DataTable getDanhSachQuocGia()
        {
            DBConnector dbc = new DBConnector();
            String sql = "";
           
            sql = "SELECT * FROM QuocGia LIMIT 100";
            return dbc.GetDataTable(sql);
        }

        public static bool insertQuocGia(String para)
        {
            DBConnector dbc = new DBConnector();
            Dictionary<String, String> data = new Dictionary<String, String>();
            data.Add("QuocGia", para);
            try
            {
                dbc.Insert("QuocGia", data);
            }
            catch (Exception crap)
            {
                MessageBox.Show(crap.Message);
                return false;
            }
            MessageBox.Show("Thêm Quốc Gia thành công!");
            return true;
        }
        public static DataTable getDanhSachDonVi()
        {
            DBConnector dbc = new DBConnector();
            String sql = "";
         
                sql = "SELECT * FROM DonVi LIMIT 100";
            return dbc.GetDataTable(sql);
        }

        public static bool insertDonVi(String para)
        {
            DBConnector dbc = new DBConnector();
            Dictionary<String, String> data = new Dictionary<String, String>();
            data.Add("DonVi", para);
            try
            {
                dbc.Insert("DonVi", data);
            }
            catch (Exception crap)
            {
                MessageBox.Show(crap.Message);
                return false;
            }
            MessageBox.Show("Thêm Đơn Vị Tính thành công!");
            return true;
        }
    }
}
